package org.servlet;

import com.google.gson.Gson;
import org.domain.Product;
import org.service.SearchAjaxService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class findPetsAjaxServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取搜索框输入的内容
        String name = request.getParameter("word");
        System.out.print(name);
        //向server层调用相应的业务
        SearchAjaxService searchAjaxService = new SearchAjaxService();
        List<String> plist = searchAjaxService.findPetsAjax(name);
        //返回结果
        Gson gson = new Gson();
        String json = gson.toJson(plist);
        System.out.println(json);

        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(json);
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doGet(request, response);

    }
}
